package io.yunho.srw.pwebflux.routerfunction.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * @author: yunho
 * @date: 2021/5/13 17:05
 * @description:
 */
@Configuration
public class CustomRouterConfig {
    @Bean
    public RouterFunction<ServerResponse> initRouterFunction(){
        return RouterFunctions.route()
                .GET("/hello/{name}",serverRequest -> {
                    String name=serverRequest.pathVariable("name");
                    System.out.println("name："+name);

                    return ServerResponse.ok().bodyValue(name);
                })
                .POST("/hello2",serverRequest -> {
                    String name=serverRequest.exchange().getRequest().getQueryParams().getFirst("name");
                    System.out.println("name："+name);

                    assert name != null;
                    return ServerResponse.ok().bodyValue(name);
                })
                .build();
    }
}
